<!--
	作者：ZhangXin
	时间：2020-07-23
	描述：博客管理页面
-->
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head th:replace="admin/fragments::head(~{::title})">
	<title>博客管理</title>
</head>

	<body>
	<!--导航-->
	<nav th:replace="admin/fragments::menu(1)"></nav>

		<div class="ui attached pointing menu">
			<div class="ui container">
				<div class="right menu">
					<a href="#" th:href="@{/admin/blogs/input}" class="item">发布</a>
					<a href="#" th:href="@{/admin/blogs}" class="active teal item">列表</a>
				</div>
			</div>

		</div>

		<!--中间内容-->
		<div class="m-container-mini m-padded-tb-big ">
			<div class="ui container">
				<div  class="ui secondary segment form">
					<input type="hidden" name="page">
					<div class="inline fields">
						<div class="field">
							<input type="text" name="title" placeholder="标题" />
						</div>
						<div class="field">
							<div class="ui labeled action input">
							<div class="ui type selection dropdown">
								<input type="hidden" name="typeId" />
								<i class="dropdown icon"></i>
								<div class="default text">分类</div>
								<div class="menu">
									<div th:each="type : ${types}" class="item" data-value="1" th:data-value="${type.id}" th:text="${type.name}">我的故事</div>

								</div>
							</div>
								<button id="clear-btn" class="ui compact secondary  button">clear</button>
							</div>
						</div>
						<div class="field">
							<div class="ui checkbox">
								<input type="checkbox" id="recommend" name="recommend" />
								<label for="recommend">推荐</label>
							</div>
						</div>
						<div class="field">
							<button type="button" id="search-btn" class="ui  teal  button"><i class="search icon"></i>搜索</button>
						</div>
					</div>
				</div>
				<div id="table-container">
					<table th:fragment="blogList" class="ui compact teal table">
						<thead>
						<tr>
							<th colspan="7"><h2 class="ui teal header" style="text-align: center">博客列表</h2></th>
						</tr>
						<tr align="center">
							<th></th>
							<th>标题</th>
							<th>类型</th>
							<th>推荐</th>
							<th>博客状态</th>
							<th>更新时间</th>
							<th>操作</th>
						</tr>
						</thead>
						<tbody>
						<tr align="center" th:each="blog,iterStat:${page.content}">
							<td th:text="${iterStat.count}">1</td>
							<td th:text="${blog.title}">刻意练习清单</td>
							<td th:text="${blog.type.name}">认知升级</td>
							<td th:text="${blog.recommend} ? '是':'否'">是</td>
							<td th:text="${blog.published} ? '发布':'草稿'">草稿</td>
							<td th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd HH:mm')}">2017-10-02 09:45</td>
							<td>
								<a href="#" class="ui mini teal basic button" th:href="@{/admin/blogs/{id}/input(id=${blog.id})}">编辑</a>
								<a href="#" onclick="return confirm('确定要删除该文章吗？')" class="ui mini red basic button" th:href="@{/admin/blogs/{id}/delete(id=${blog.id})}">删除</a>
							</td>
						</tr>
						</tbody>
						<tfoot>
						<tr>
							<th colspan="7">
								<div class="ui inverted divided stackable grid">
									<div class="three wide column" align="center">
										<a onclick="page(this)" th:attr="data-page=${page.number}-1" class="ui mini teal basic button item" th:unless="${page.first}">上一页</a>
									</div>

									<div class="ten wide column" align="center">
										<p>第 <span>[[${page.number}+1]]</span> 页，共 <span>[[${page.totalPages}]]</span> 页，有 <span>[[${page.totalElements}]]</span> 篇文章</p>
									</div>

									<div class="three wide column" align="center">
										<a onclick="page(this)" th:attr="data-page=${page.number}+1" class="ui mini teal basic button item" th:unless="${page.last}">下一页</a>
									</div>
								</div>
								<div align="center">
										<a href="#" th:href="@{/admin/blogs/input}" type="button" class="ui teal button m-mobile-wide m-margin-top"><i class="pencil icon"></i>新增</a>
								</div>
							</th>
						</tr>
						</tfoot>
					</table>
				</div>

				<div class="ui success message" th:unless="${#strings.isEmpty(successMessage)}">
					<i class="close icon"></i>
					<div class="" th:text="${successMessage}">提示：操作成功！</div>
				</div>
				<div class="ui negative message" th:unless="${#strings.isEmpty(errorMessage)}">
					<i class="close icon"></i>
					<div class="" th:text="${errorMessage}">提示：操作失败！</div>
				</div>
			</div>
		</div>

		<!--底部内容-->
		<footer th:replace="admin/fragments::footer"></footer>

	    <script th:replace="admin/fragments::script"></script>

		<script>
			$('.menu.toggle').click(function() {
				$('.m-item').toggleClass('m-mobile-hide')
			})

			$('.menu.toggle').click(function() {
				$('.m-item').toggleClass('m-mobile-show');

			});

			$('.ui.dropdown').dropdown({
				on: 'hover'
			});

			//消息提示关闭初始化
			$('.message .close')
				.on('click', function() {
					$(this)
						.closest('.message')
						.transition('fade');
				});

			function page(obj) {
				$("[name='page']").val($(obj).data("page"));
				loaddata();
			}

			$("#search-btn").click(function () {
				$("[name='page']").val(0);
				loaddata();
			});
			function loaddata() {
				$("#table-container").load(/*[[@{/admin/blogs/search}]]*/"/admin/blogs/search",{
					title : $("[name='title']").val(),
					typeId : $("[name='typeId']").val(),
					recommend : $("[name='recommend']").prop('checked'),
					page : $("[name='page']").val()
				});
			}

			//清除搜索条件
			$('#clear-btn')
					.on('click', function() {
						$('.ui.type.dropdown')
								.dropdown('clear');
					});
		</script>
	</body>

</html>